package ltd.dujiabao.capability.domain.rulemng;

import ltd.dujiabao.capability.domain.capmng.cap.Capability;
import ltd.dujiabao.capability.domain.capmng.cap.CapabilityRepository;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/13 12:08
 * @Desc :
 */
public class Support {
    private final SupportIdentity identity;
    private final RuleRepository ruleRepository;
    private final CapabilityRepository capabilityRepository;
    private final boolean support;

    public Support(SupportIdentity identity, RuleRepository ruleRepository,
                   CapabilityRepository capabilityRepository) {
        this.identity = identity;
        this.ruleRepository = ruleRepository;
        this.capabilityRepository = capabilityRepository;
        support = initSupport();
    }

    private boolean initSupport() {
        Rule rule = ruleRepository.findByFuncName(identity.getFuncName());
        Capability capability = capabilityRepository.findByIdentity(identity.getIdentity());
        return rule.checkIfSupport(capability);
    }

    public boolean support() {
        return support;
    }
}
